home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
c01lab4.zip
/
LRMRDR
/
LRM_CHAP.ZIP
/
CHAP09.DOC
< prev
next >
Wrap
Text File
|
1992-04-21
|
57KB
|
1,374 lines
> 9. Tasks
The execution of a program that does not contain a task is defined in terms
of a sequential execution of its actions, according to the rules described
in other chapters of this manual. These actions can be considered to be
executed by a single logical processor.
Tasks are entities whose executions proceed in parallel in the following
sense. Each task can be considered to be executed by a logical processor
of its own. Different tasks (different logical processors) proceed
independently, except at points where they synchronize.
Some tasks have entries. An entry of a task can be called by other tasks.
A task accepts a call of one of its entries by executing an accept
statement for the entry. Synchronization is achieved by rendezvous between
a task issuing an entry call and a task accepting the call. Some entries
have parameters; entry calls and accept statements for such entries are
the principal means of communicating values between tasks.
The properties of each task are defined by a corresponding task unit which
consists of a task specification and a task body. Task units are one of
the four forms of program unit of which programs can be composed. The
other forms are subprograms, packages and generic units. The properties of
task units, tasks, and entries, and the statements that affect the
interaction between tasks (that is, entry call statements, accept
statements, delay statements, select statements, and abort statements) are
described in this chapter.
Note:
Parallel tasks (parallel logical processors) may be implemented on
multicomputers, multiprocessors, or with interleaved execution on a single
physical processor. On the other hand, whenever an implementation can
detect that the same effect can be guaranteed if parts of the actions of a
given task are executed by different physical processors acting in
parallel, it may choose to execute them in this way; in such a case,
several physical processors implement a single logical processor.
References: abort statement 9.10, accept statement 9.5, delay statement
9.6, entry 9.5, entry call statement 9.5, generic unit 12, package 7,
parameter in an entry call 9.5, program unit 6, rendezvous 9.5, select
statement 9.7, subprogram 6, task body 9.1, task specification 9.1
> 9.1 Task Specifications and Task Bodies
A task unit consists of a task specification and a task body. A task
specification that starts with the reserved words task type declares a
task type. The value of an object of a task type designates a task having
the entries, if any, that are declared in the task specification; these
entries are also called entries of this object. The execution of the task
is defined by the corresponding task body.
A task specification without the reserved word type defines a single task.
A task declaration with this form of specification is equivalent to the
declaration of an anonymous task type immediately followed by the
declaration of an object of the task type, and the task unit identifier
names the object. In the remainder of this chapter, explanations are given
in terms of task type declarations; the corresponding explanations for
single task declarations follow from the stated equivalence.
task_declaration ::= task_specification;
task_specification ::=
task [type] identifier [is
{entry_declaration}
{representation_clause}
end [task_simple_name]]
task_body ::=
task body task_simple_name is
[declarative_part]
begin
sequence_of_statements
[exception
exception_handler
{exception_handler}]
end [task_simple_name];
The simple name at the start of a task body must repeat the task unit
identifier. Similarly if a simple name appears at the end of the task
specification or body, it must repeat the task unit identifier. Within a
task body, the name of the corresponding task unit can also be used to
refer to the task object that designates the task currently executing the
body; furthermore, the use of this name as a type mark is not allowed
within the task unit itself.
For the elaboration of a task specification, entry declarations and
representation clauses, if any, are elaborated in the order given. Such
representation clauses only apply to the entries declared in the task
specification (see 13.5).
The elaboration of a task body has no other effect than to establish that
the body can from then on be used for the execution of tasks designated by
objects of the corresponding task type.
The execution of a task body is invoked by the activation of a task object
of the corresponding type (see 9.3). The optional exception handlers at
the end of a task body handle exceptions raised during the execution of the
sequence of statements of the task body (see 11.4).
Examples of specifications of task types:
task type RESOURCE is
entry SEIZE;
entry RELEASE;
end RESOURCE;
task type KEYBOARD_DRIVER is
entry READ (C : out CHARACTER);
entry WRITE(C : in CHARACTER);
end KEYBOARD_DRIVER;
Examples of specifications of single tasks:
task PRODUCER_CONSUMER is
entry READ (V : out ITEM);
entry WRITE(E : in ITEM);
end;
task CONTROLLER is
entry REQUEST(LEVEL)(D : ITEM); -- a family of entries
end CONTROLLER;
task USER; -- has no entries
Example of task specification and corresponding body:
task PROTECTED_ARRAY is
-- INDEX and ITEM are global types
entry READ (N : in INDEX; V : out ITEM);
entry WRITE(N : in INDEX; E : in ITEM);
end;
task body PROTECTED_ARRAY is
TABLE : array(INDEX) of ITEM := (INDEX => NULL_ITEM);
begin
loop
select
accept READ (N : in INDEX; V : out ITEM) do
V := TABLE(N);
end READ;
or
accept WRITE(N : in INDEX; E : in ITEM) do
TABLE(N) := E;
end WRITE;
end select;
end loop;
end PROTECTED_ARRAY;
Note:
A task specification specifies the interface of tasks of the task type with
other tasks of the same or of different types, and also with the main
program.
References: declaration 3.1, declarative part 3.9, elaboration 3.9, entry
9.5, entry declaration 9.5, exception handler 11.2, identifier 2.3, main
program 10.1, object 3.2, object declaration 3.2.1, representation clause
13.1, reserved word 2.9, sequence of statements 5.1, simple name 4.1, type
3.3, type declaration 3.3.1
> 9.2 Task Types and Task Objects
A task type is a limited type (see 7.4.4). Hence neither assignment nor
the predefined comparison for equality and inequality are defined for
objects of task types; moreover, the mode out is not allowed for a formal
parameter whose type is a task type.
A task object is an object whose type is a task type. The value of a task
object designates a task that has the entries of the corresponding task
type, and whose execution is specified by the corresponding task body. If
a task object is the object, or a subcomponent of the object, declared by
an object declaration, then the value of the task object is defined by the
elaboration of the object declaration. If a task object is the object, or
a subcomponent of the object, created by the evaluation of an allocator,
then the value of the task object is defined by the evaluation of the
allocator. For all parameter modes, if an actual parameter designates a
task, the associated formal parameter designates the same task; the same
holds for a subcomponent of an actual parameter and the corresponding
subcomponent of the associ